package vip.youngboy.freejump.db;

import org.springframework.jdbc.core.JdbcTemplate;
import vip.youngboy.freejump.db.constrants.DBType;
import vip.youngboy.freejump.db.model.DBColumn;
import vip.youngboy.freejump.db.model.DBTable;

import java.util.*;

/**
 * 数据库操作
 */
public abstract class DBHelper {

    protected JdbcTemplate jdbcTemplate;

    public abstract DBType supportType();

    public abstract TableOperator createTableOperator(DBTable<? extends DBColumn> DBTable, JdbcTemplate jdbcTemplate);

    public abstract Map<String, String> getTableNames(String tableName);

    public abstract List<String> getViewNames(String viewName);

    public abstract DBTable<DBColumn> getTable(String tableName);

    public abstract DBTable<DBColumn> getView(String viewName);

    public abstract boolean supportPartition(String tableName);

    public abstract boolean isExsitPartition(String tableName, String partName);

    public abstract void createPartition(String tableName, String partName);

    public Object getOrDefault(Map<?, ?> map, Object key, Object defVal) {
        if (!map.containsKey(key)) {
            return defVal;
        } else {
            Object val = map.get(key);
            return val == null ? defVal : val;
        }
    }

}
